package com.framework.utils.string;

import com.framework.view.SeparatMonthView;
import com.framework.view.TransactionListView;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.*;

/**
* Description:日期工具类 
* @ClassName: DateUtils 
* @author Jalf
* @since 2016年6月2日 下午2:44:02 
* Copyright  foxtail All right reserved.
 */
public class DateStrUtils {
	public static final String Y ="yyyy";
	
	public static final String YMD = "yyyyMMdd";
	
	public static final String YMDHMS = "yyyyMMdd HH:mm:ss";
	
	public static final String Y_M_D = "yyyy-MM-dd";
	
	public static final String Y_M_DHMS = "yyyy-MM-dd HH:mm:ss";
	
	public static final String YMDHMSS="yyyyMMddhhmmssSSS";
	
	/**
	* Description:根据毫秒数转换为时间    
	* @Title: getTime  
	* @author Jalf
	* @since 2016年6月2日 下午2:45:20
	* @param millseconds
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static String getTime(Long millseconds) {
		String time = "";
		if (millseconds == null) {
			return "";
		}
		int days = (int) millseconds.longValue() / 1000 / 60 / 60 / 24;
		if (days > 0) {
			time = time + days + "天";
		}
		long hourMillseconds = millseconds.longValue() - days * 1000 * 60 * 60 * 24;
		int hours = (int) hourMillseconds / 1000 / 60 / 60;
		if (hours > 0) {
			time = time + hours + "小时";
		}
		long minuteMillseconds = millseconds.longValue() - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60;

		int minutes = (int) minuteMillseconds / 1000 / 60;
		if (minutes > 0) {
			time = time + minutes + "分钟";
		}
		
		long secondMillseconds = millseconds.longValue() - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60 - minutes * 1000 * 60;
		int second = (int) secondMillseconds / 1000;
		if (second > 0) {
			time = time + second + "秒";
		}
		return time;
	}
	
	/**
	* Description:获取当前时间字符串    
	* @Title: getCurrTimeForString  
	* @author Jalf
	* @since 2016年6月2日 下午2:46:24
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static String getCurrTimeForString(){
		return formatDate(new Date(), Y_M_DHMS);
	}
	
	/**
	* Description:获取当前日期字符串    
	* @Title: getCurrDateForString  
	* @author Jalf
	* @since 2016年6月2日 下午2:46:47
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static String getCurrDateForString(){
		return formatDate(new Date(), YMD);
	}
	
	/**
	* Description:格式化日期成字符串    
	* @Title: formatDate  
	* @author Jalf
	* @since 2016年6月2日 下午2:47:29
	* @param date
	* @param pattern
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static String formatDate(Date date,String pattern)
	{
		SimpleDateFormat format = new SimpleDateFormat(pattern);
		return format.format(date);
	}

	/**
	 * 把long 转换成 日期 再转换成String类型
	 */
	public  static  String transferLongToDate(String dateFormat, Long millSec) {
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		Date date = new Date(millSec);
		return sdf.format(date);
	}

	/**
	* Description:将格式日期的字符串解析成Date    
	* @Title: parseDate  
	* @author Jalf
	* @since 2016年6月2日 下午2:47:55
	* @param dateStr
	* @param pattern
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date parseDate(String dateStr,String pattern)
	{
		try {
			SimpleDateFormat format = new SimpleDateFormat(pattern);
			return format.parse(dateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	* Description:计算两个时间的时间差    
	* @Title: getIntervalForTwoDate  
	* @author Jalf
	* @since 2016年6月2日 下午2:48:43
	* @param startDate
	* @param endDate
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static String getIntervalForTwoDate(Date startDate,Date endDate)
	{
		if(null!=startDate&&null!=endDate)
		{
			long t1 = startDate.getTime();
			long t2 = endDate.getTime();
			int hours=(int) ((t2 - t1)/3600000);
	        int minutes=(int) (((t2 - t1)/1000-hours*3600)/60);
	        int second=(int) ((t2 - t1)/1000-hours*3600-minutes*60);
	        return ""+hours+"小时"+minutes+"分"+second+"秒";
		}
		return "";
	}

	/**
	* Description:按calendar的类型获取时间数    
	* @Title: getDateField  
	* @author Jalf
	* @since 2016年6月2日 下午2:49:02
	* @param date
	* @param field
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static int getDateField(Date date,int field) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(field);
	}

	/**
	 * 计算两个时间的相差年数
	* Description:    
	* @Title: getYearsBetweenDate  
	* @author Jalf
	* @since 2016年6月2日 下午2:49:41
	* @param begin
	* @param end
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static int getYearsBetweenDate(Date begin,Date end){
		int bYear = getDateField(begin,Calendar.YEAR);
		int eYear = getDateField(end,Calendar.YEAR);
		return eYear - bYear;
	}
	
	/**
	* Description:计算两个时间相差的天数    
	* @Title: getDaysBetweenDate  
	* @author Jalf
	* @since 2016年6月2日 下午2:50:09
	* @param begin
	* @param end
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static int getDaysBetweenDate(Date begin,Date end){
		int bDay = getDateField(begin,Calendar.DAY_OF_YEAR);
		int eDay = getDateField(end,Calendar.DAY_OF_YEAR);
		return eDay - bDay;
	}

	/**
	* Description:获取date年后(前)的amount年的第一天的开始时间    
	* @Title: getSpecficYearStart  
	* @author Jalf
	* @since 2016年6月2日 下午2:50:29
	* @param date
	* @param amount
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date getSpecficYearStart(Date date,int amount) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.YEAR, amount);
		cal.set(Calendar.DAY_OF_YEAR, 1);
		return getStartDate(cal.getTime());
	}

	/**
	* Description:获取date年后的amount年的最后一天的终止时间    
	* @Title: getSpecficYearEnd  
	* @author Jalf
	* @since 2016年6月2日 下午2:50:55
	* @param date
	* @param amount
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date getSpecficYearEnd(Date date,int amount) {
		Date temp = getStartDate(getSpecficYearStart(date,amount + 1));
		Calendar cal = Calendar.getInstance();
		cal.setTime(temp);
		cal.add(Calendar.DAY_OF_YEAR, -1);
		return getFinallyDate(cal.getTime());
	}

	/**
	* Description:获取date月后的amount月的第一天的开始时间    
	* @Title: getSpecficMonthStart  
	* @author Jalf
	* @since 2016年6月2日 下午2:51:11
	* @param date
	* @param amount
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date getSpecficMonthStart(Date date,int amount) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, amount);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		return getStartDate(cal.getTime());
	}

	/**
	* Description:获取当前自然月后的amount月的最后一天的终止时间    
	* @Title: getSpecficMonthEnd  
	* @author Jalf
	* @since 2016年6月2日 下午2:51:46
	* @param date
	* @param amount
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date getSpecficMonthEnd(Date date,int amount) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(getSpecficMonthStart(date,amount + 1));
		cal.add(Calendar.DAY_OF_YEAR, -1);
		return getFinallyDate(cal.getTime());
	}

	/**
	 * 
	* Description:获取date周后的第amount周的开始时间（这里星期一为一周的开始）    
	* @Title: getSpecficWeekStart  
	* @author Jalf
	* @since 2016年6月2日 下午2:52:06
	* @param date
	* @param amount
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date getSpecficWeekStart(Date date,int amount) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.setFirstDayOfWeek(Calendar.MONDAY); /* 设置一周的第一天为星期一 */
		cal.add(Calendar.WEEK_OF_MONTH, amount);
		cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
		return getStartDate(cal.getTime());
	}

	/**
	* Description:获取date周后的第amount周的最后时间（这里星期日为一周的最后一天）    
	* @Title: getSpecficWeekEnd  
	* @author Jalf
	* @since 2016年6月2日 下午2:55:17
	* @param date
	* @param amount
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date getSpecficWeekEnd(Date date,int amount) {
		Calendar cal = Calendar.getInstance();
		cal.setFirstDayOfWeek(Calendar.MONDAY); /* 设置一周的第一天为星期一 */
		cal.add(Calendar.WEEK_OF_MONTH, amount);
		cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		return getFinallyDate(cal.getTime());
	}

	/**
	* Description:得到指定日期的一天的的最后时刻23:59:59    
	* @Title: getFinallyDate  
	* @author Jalf
	* @since 2016年6月2日 下午2:54:57
	* @param date
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date getFinallyDate(Date date) {
		String temp = formatDate(date,YMD);
		temp += " 23:59:59";
		return parseDate(temp,YMDHMS);
	}

	/**
	* Description:得到指定日期的一天的开始时刻00:00:00    
	* @Title: getStartDate  
	* @author Jalf
	* @since 2016年6月2日 下午2:54:27
	* @param date
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date getStartDate(Date date) {
		String temp = formatDate(date,YMD);
		temp += " 00:00:00";
		return parseDate(temp, YMDHMS);
	}

	/**
	* Description:拿到当前月的最后一天    
	* @Title: getLastDayOfMonth  
	* @author Jalf
	* @since 2016年6月2日 下午2:53:56
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static Date getLastDayOfMonth(){
		Calendar calendar = Calendar.getInstance();  
		calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));  
		 return calendar.getTime();
	}
	
	/**
	* Description:判断传入的日期是否是周末    
	* @Title: isWeek  
	* @author Jalf
	* @since 2016年6月2日 下午2:53:35
	* @param currentDate
	* @return
	* Copyright  foxtail All right reserved.
	 */
	public static boolean isWeek(Date currentDate) {  
		int currentDay = 9  ;  
		if(null!=currentDate){
 			currentDay = currentDate.getDay();
		}
        return currentDay == 0 || currentDay == 6;
    }
	
	/**
	 * 将未指定格式的日期字符串转化成
	* Description:    
	* @Title: parseStringToDate  
	* @author Jalf
	* @since 2016年6月2日 下午2:53:24
	* @param date
	* @return
	* Copyright  foxtail All right reserved.
	 */
    public static Date parseStringToDate(String date) {  
        Date result = null;  
        String parse = date;  
        parse = parse.replaceFirst("^[0-9]{4}([^0-9]?)", "yyyy$1");  
        parse = parse.replaceFirst("^[0-9]{2}([^0-9]?)", "yy$1");  
        parse = parse.replaceFirst("([^0-9]?)[0-9]{1,2}([^0-9]?)", "$1MM$2");  
        parse = parse.replaceFirst("([^0-9]?)[0-9]{1,2}( ?)", "$1dd$2");  
        parse = parse.replaceFirst("( )[0-9]{1,2}([^0-9]?)", "$1HH$2");  
        parse = parse.replaceFirst("([^0-9]?)[0-9]{1,2}([^0-9]?)", "$1mm$2");  
        parse = parse.replaceFirst("([^0-9]?)[0-9]{1,2}([^0-9]?)", "$1ss$2");  
        DateFormat format = new SimpleDateFormat(parse);  
        try {
			result = format.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}  
        return result;  
    } 

    public  static long getNextTime(int timeUnit, int interval, long timeMill)
      {
        Calendar ca = Calendar.getInstance();
        ca.setTimeInMillis(timeMill);
        switch (timeUnit) {
        case 0:
          ca.add(13, interval);
          break;
        case 1:
          ca.add(12, interval);
          break;
        case 2:
          ca.add(10, interval);
          break;
        case 3:
          ca.add(5, interval);
          break;
        case 4:
          ca.add(2, interval);
          break;
        default:
          return 0L;
        }
        return ca.getTimeInMillis();
      }
    
    public static Date getMillis(Date startTime,int timeMill){
		 Calendar cal = Calendar.getInstance();
		 cal.setTimeInMillis(startTime.getTime());
		 cal.add(Calendar.MINUTE,timeMill);
		return cal.getTime();
    }
    
    /**
    * Description:获得指定日期的几天     
    * @Title: getSpecifiedDayAfter  
    * @author Jalf
    * @since 2016年6月2日 下午2:52:57
    * @param specifiedDate
    * @param number
    * @return
    * Copyright  foxtail All right reserved.
     */
    public static Date getSpecifiedDayAfter(Date specifiedDate,int number){ 
		Calendar c = Calendar.getInstance();     
		c.setTime(specifiedDate); 
		int day=c.get(Calendar.DATE); 
		c.set(Calendar.DATE,day+number); 
		
		return c.getTime(); 
    }

 
    /**
    * Description:两个时间相差的秒数    
    * @Title: getSecondDiff  
    * @author Jalf
    * @since 2016年6月2日 下午2:52:37
    * @param startTime
    * @param endTime
    * @return
    *
     */
    public static Long getSecondDiff(Date startTime,Date endTime){
        long start = startTime.getTime();
        long end = endTime.getTime();
        return end - start;

    }

	public static String getYesterdayStr(String format) {
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, -1);
		return new SimpleDateFormat(format).format(cal.getTime());
	}

	 public static Date strToDate(String strDate) {
		    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		    ParsePosition pos = new ParsePosition(0);
		    Date strtodate = formatter.parse(strDate, pos);
		    return strtodate;
    }
	/**
	 * 获取当前月份最后一天
	 *
	 * @return
	 * @throws ParseException
	 */
	public static String getMaxMonthDate() {
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return dft.format(calendar.getTime());
	}

	public static String getPerFirstDayOfMonth() {
		SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, 0);
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		return dft.format(calendar.getTime());

	}

	public static String getDifferDate(Integer differDate){
		Date date=new Date();//取时间
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.add(Calendar.DATE,differDate);//把日期往前减少一天，若想把日期向后推一天则将负数改为正数
		date=calendar.getTime();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = formatter.format(date);
		return dateString;
	}

	/**
	 * 时间格式转换
	 * @param dateDate
	 * @return
	 */
	 public static String dateToStr(Date dateDate) {
		    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		    String dateString = formatter.format(dateDate);
		    return dateString;
		 }


    public static boolean judgeDateOverdue(Date res){
	 	//获取当前时间
		String date = StringUtil.getDateTime();
	 	boolean overdue = false;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String beginTime = formatter.format(res);
		try {
			Date sd1= formatter.parse(beginTime);
			Date sd2= formatter.parse(date);
			overdue = sd1.before(sd2);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return  overdue;
	}

	public static List<String> getMonthBetween(String minDate, String maxDate) {
		ArrayList<String> result = new ArrayList<String>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
		Calendar min = Calendar.getInstance();
		Calendar max = Calendar.getInstance();
		try {
			min.setTime(sdf.parse(minDate));
			min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
			max.setTime(sdf.parse(maxDate));
			max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar curr = min;
		while (curr.before(max)) {
			result.add(sdf.format(curr.getTime()));
			curr.add(Calendar.MONTH, 1);
		}
		return result;
	}

	  public static Date strToDateLong(String strDate) {
		    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		    ParsePosition pos = new ParsePosition(0);
		    Date strtodate = formatter.parse(strDate, pos);
		    return strtodate;
		 }
	  

	public static List<TransactionListView> getBetweenDates(String dateFirst, String dateSecond){
		List<TransactionListView> result = new ArrayList<>();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try{
			Date dateOne = dateFormat.parse(dateFirst);
			Date dateTwo = dateFormat.parse(dateSecond);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(dateOne);
			while(calendar.getTime().before(dateTwo)){
				String data = dateFormat.format(calendar.getTime());
				TransactionListView s = new TransactionListView();
				s.setTime(data);
				s.setAmount(new BigDecimal("0.00"));
				result.add(s);
				calendar.add(Calendar.DAY_OF_MONTH, 1);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		Collections.reverse(result); //倒叙
		return result;
	}

	public static void main(String[] args) {

		System.out.println(getBetweenDates("2018-11-01","2018-11-15"));
	}


	/**
	 * 调取方法
	 * @param year 年
	 * @param month 月
	 * @param weeks 第几周
	 * @return 返回第几周的开始与结束日期
	 */
	public static Map<String,Object> getScopeForweeks(int year,int month,int weeks){
		Map<String,Object> map=new HashMap<String, Object>();
		String time=year+"-"+getMonthToStr(month);
		Map<String, Object> result = getDateScope(time);
		//获取天数和周数
		int resultDays=Integer.parseInt(result.get("days").toString());
		int resultWeeks=Integer.parseInt(result.get("weeks").toString());
		/**
		 * 如果参数周数大于实际周数
		 * 则返回一个不存在的日期
		 * 默认设置为当前 天数+1
		 */
		if(weeks>resultWeeks){
			int days=resultDays+1;
			String beginDate=year+"-"+getMonthToStr(month)+"-"+days;
			map.put("beginDate",beginDate);
			map.put("endDate",beginDate);
		}else{
			//获取当月第一天属于周几
			Map<Integer, Object> scopes = getScope(time, resultDays, resultWeeks);
			map=(Map<String,Object>)scopes.get(weeks);
		}
		return map;
	}
	/**
	 *获取某年某月的天数以及周数
	 * @param(格式：yyyy-MM)
	 * @return
	 */
	private static Map<String,Object> getDateScope(String time){
		Map<String,Object> map=new HashMap<String, Object>();
		try{
			//保证日期位数
			if(time.length()<=7){
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				Date date=sdf.parse(time+"-01");
				Calendar c = Calendar.getInstance();
				c.setTime(date);
				//获取天数
				int days = c.getActualMaximum(Calendar.DAY_OF_MONTH);
				//获取周数
				int weeks = c.getActualMaximum(Calendar.WEEK_OF_MONTH);
				map.put("days",days);
				map.put("weeks",weeks);
			}else {
				throw new RuntimeException("日期格式不正确");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return map;
	}
	/**
	 *获取本月周区间
	 * @param date(yyyy-mm)日期
	 * @param days 天数
	 * @param weeks 周数
	 * @return
	 */
	private static Map<Integer,Object> getScope(String date,int days,int weeks){
		Map<Integer,Object> map=new HashMap<Integer, Object>();
		//遍历周数
		int midNum=0;
		for(int i=1;i<=weeks;i++){
			//第一周
			if(i==1){
				String time=date+"-01";
				String week=getWeekOfDate(time);
				//获取第一周还有多少天
				int firstDays = getSurplusDays(week);
				//获取第一周结束日期
				int endDays=1+firstDays;
				String time2=date+"-0"+endDays;
				Map<String,Object> data=new HashMap<String, Object>();
				data.put("beginDate",time);
				data.put("endDate",time2);
				map.put(i,data);
				//
				midNum=endDays;
			}else{
				//当前日期数+7 比较 当月天数
				if((midNum+7)<=days){
					int beginNum=midNum+1;
					System.out.println("begin:"+beginNum);

					int endNum=midNum+7;
					System.out.println("end:"+endNum);

					String time1=date+"-"+getNum(beginNum);
					String time2=date+"-"+getNum(endNum);
					Map<String,Object> data=new HashMap<String, Object>();
					data.put("beginDate",time1);
					data.put("endDate",time2);
					map.put(i,data);
					midNum=endNum;
				}else{
					int beginNum=midNum+1;
					int endNum=days;
					String time1=date+"-"+getNum(beginNum);
					String time2=date+"-"+getNum(endNum);
					Map<String,Object> data=new HashMap<String, Object>();
					data.put("beginDate",time1);
					data.put("endDate",time2);
					map.put(i,data);
					midNum=endNum;
				}
			}
		}

		return map;
	}
	/**
	 *获取日期属于周几
	 * @param time(格式：yyyy-MM-dd)
	 * @return
	 * @throws Exception
	 */
	private static String getWeekOfDate(String time){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String week="";
		try{
			Date date=sdf.parse(time);
			String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
			if (w < 0) {
				w = 0;
			}
			week= weekDays[w];
		}catch(Exception e){
			e.printStackTrace();
		}
		return week;
	}
	/**
	 * 获取数字
	 * @return
	 */
	private static String getNum(int num){
		int result=num/10;
		if(result==0){
			return "0"+num;
		}else{
			return num+"";
		}
	}
	/**
	 * 返回月份的字符串
	 * @param month
	 * @return
	 */
	private static String getMonthToStr(int month){
		String str="";
		switch (month){
			case 1:
				str="01";
				break;
			case 2:
				str="02";
				break;
			case 3:
				str="03";
				break;
			case 4:
				str="04";
				break;
			case 5:
				str="05";
				break;
			case 6:
				str="06";
				break;
			case 7:
				str="07";
				break;
			case 8:
				str="08";
				break;
			case 9:
				str="09";
				break;
			case 10:
				str="10";
				break;
			case 11:
				str="11";
				break;
			case 12:
				str="12";
				break;
		}
		return str;
	}
	/**
	 * 根据当前周几判断当前周还有几天
	 * @param week{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}
	 * @return
	 */
	private static int getSurplusDays(String week){
		int num=0;
		if("星期日".equals(week)){
			num=0;
		}else if("星期一".equals(week)){
			num=6;
		}else if("星期二".equals(week)){
			num=5;
		}else if("星期三".equals(week)){
			num=4;
		}else if("星期四".equals(week)){
			num=3;
		}else if("星期五".equals(week)){
			num=2;
		}else if("星期六".equals(week)){
			num=1;
		}
		return num;
	}

	/**
	 * 获取指定年月的最后一天
	 * @param year
	 * @param month
	 * @return
	 */
	public static String getLastDayOfMonth1(int year, int month) {
		Calendar cal = Calendar.getInstance();
		//设置年份
		cal.set(Calendar.YEAR, year);
		//设置月份
		cal.set(Calendar.MONTH, month-1);
		//获取某月最大天数
		int lastDay = cal.getActualMaximum(Calendar.DATE);
		//设置日历中月份的最大天数
		cal.set(Calendar.DAY_OF_MONTH, lastDay);
		//格式化日期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(cal.getTime());
	}

}
